package com.hilon.foundation.base;

import com.hilon.foundation.para.ConditionPara;
import com.hilon.foundation.util.ResultBean;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

public class BaseController<T extends EntityBaseId,V> {
    protected BaseService<T,V> service;
    protected void setService(BaseService<T,V> service){
        this.service=service;
    }
    @PostMapping("/append")
    public ResultBean<String> append(@RequestBody T entity) {
        System.out.println("增加一行");
        System.out.println(entity);
        entity.handleChildren();
        return service.append(entity);
    }

    @PostMapping("/deleteById/{idPara}")
    public ResultBean<String> deleteById(@PathVariable Long idPara) {
        return service.deleteById(idPara);
    }
    @PostMapping("/deleteByIds")
    public ResultBean<String> deleteByIds(@RequestBody List<Long> ids) {
        System.out.println("批量删除");
        System.out.println(ids);
        return service.deleteByIds(ids);
    }

    @PostMapping("/edit")
    public ResultBean<String> edit(@RequestBody T entity) {
        entity.handleChildren();
        return service.edit(entity);
    }

    @PostMapping("/findById/{idPara}")
    public ResultBean<V> findById(@PathVariable Long idPara) {
        return service.findById(idPara);
    }

    @PostMapping("/findAll")
    public ResultBean<List<V>> findAll() {
        return service.findAll();
    }
    @PostMapping("/findByCondition")
    public ResultBean<List<V>> findByCondition(@RequestBody ConditionPara conditionPara) {
        System.out.println(conditionPara);
        return service.findByCondition(conditionPara);
    }
    @PostMapping("/findAllWithDeleted")
    public ResultBean<List<V>> findAllWithDeleted() {
        return service.findAllWithDeleted();
    }
}
